import React from "react";
import {withRouter} from "react-router-dom";
import {inject, observer} from "mobx-react";
import {WrOperateLog, WrAlertPage} from "../../../public";
import {Tools} from "weaver-mobile";
import AccessHeader from "./header";

const getLabel = Tools.getLabel;

/**
 * 评分-日志
 */
@inject("accessViewStore")
@withRouter
@observer
export default class Log extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.accessViewStore;
    }

    componentWillMount() {
        if(this.store.canlog){
            this.store.getAccessLogInfo(false);
        }
    }

    render() {
        const {logStore, msg,canlog} = this.store;
        if (msg == "noinfo") {
            return <WrAlertPage height={"100vh"} show msg={getLabel(508609, "您暂时无权限查看此数据")}/>
        }
        return [
            <AccessHeader showMsg={getLabel(32061, "操作日志")}/>,
             <div className="roll">
                 {canlog?<WrOperateLog
                     logStore={logStore}
                     handleRefresh={this.handleRefresh}
                     handleEndReached={this.handleEndReached}
                 />:<WrAlertPage height={"100vh"} show msg={getLabel(508609, "您暂时无权限查看此数据")}/>}

            </div>
        ]
    }

    //下拉刷新
    handleRefresh = () => {
        const {logStore, getAccessLogInfo} = this.store;
        this.store.currentpage = 1
        getAccessLogInfo(false);
    }

    //底部加载
    handleEndReached = () => {
        const {getAccessLogInfo} = this.store;
        this.store.currentpage = this.store.currentpage + 1;
        getAccessLogInfo(true);
    }

}